package cn.zhouchao.user.controller;

import cn.zhouchao.basic.dto.WechatBinderDto;
import cn.zhouchao.basic.dto.WechatDto;
import cn.zhouchao.basic.util.AjaxResult;
import cn.zhouchao.user.dto.AccountDto;
import cn.zhouchao.user.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.Map;

/**
 * 后台登录接口
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    /**
     * 账号密码登录--前台+后台
     * @param dto
     * @return
     */
    @PostMapping("/account")
    public AjaxResult accountLogin(@RequestBody @Valid AccountDto dto){
        System.out.println("接口controller——5");
//        try {
//             Map<String,Object> map = loginService.account(dto);
//             return AjaxResult.me().success(map);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return AjaxResult.me().fail();
//        }
        return loginService.account(dto);

    }

    /**
     * 微信登录——获取code
     * @param dto
     * @return
     */
    @PostMapping("/wechat")
    public AjaxResult wechatLogin(@RequestBody @Valid WechatDto dto){
        return loginService.wechat(dto);
    }

    /**
     * 微信登录——绑定-校验-加数据
     * @return
     */
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinderLogin(@RequestBody @Valid WechatBinderDto dto){
        return loginService.binder(dto);
    }

}
